package game.web.controller;

import game.web.base.Constants;
import game.web.dao.dto.WithdrawDTO;
import game.web.entity.WithdrawEntityManager;
import game.web.struts.WithdrawForm;
import projectx.core.base.ProjectXSystemException;
import projectx.core.base.ProjectXUserException;
import projectx.transaction.TransactionHandler;
import projectx.util.ClassUtil;
import projectx.util.TicketUtil;
import projectx.web.base.ConstantsProjectX;
import projectx.web.base.ProjectXDbTrxController;
import projectx.web.base.ProjectXForm;
import projectx.web.base.UserContext;

public class WithdrawControllor extends ProjectXDbTrxController {

	protected WithdrawControllor(UserContext uc, ProjectXForm form) {
		super(uc, form);
	}

	@Override
	public Object execute() throws ProjectXUserException,
			ProjectXSystemException {

		debugBegin();

		UserContext uc = getUc();

		WithdrawForm form = (WithdrawForm) getForm();
		
		WithdrawDTO dto = new WithdrawDTO();

		String ip = (String) uc.get(ConstantsProjectX.CURRENT_IP);
		String userid = (String) uc.get(ConstantsProjectX.USER_ID);
		ClassUtil.copyData(form, dto);
		dto.setId(TicketUtil.getTicket(Constants.WITHDRAW_INDEX));
		dto.setUserid(userid);
		dto.setBankinfo(form.getBankinfo());
		dto.setMoney(form.getMoney());
		dto.setCreatetime(getCurrentTimeString());
		dto.setUpdatetime(getCurrentTimeString());
		dto.setCreateip(ip);
		dto.setUpdateip(ip);
		
		WithdrawEntityManager.insert(dto);
		uc.put(Constants.WITHDRAW_ACION, dto);

		debugEnd();
		return null;
	}

	public static Object execute(UserContext uc, ProjectXForm form)
			throws ProjectXUserException, ProjectXSystemException {
		return TransactionHandler.call(new WithdrawControllor(uc, form));
	}
}
